Given an array of strings, group anagrams together.
Input: ["eat", "tea", "tan", "ate", "nat", "bat"] Output: [ ["ate","eat","tea"], ["nat","tan"], ["bat"] ]
- All inputs will be in lowercase.
- The order of your output does not matter.
use std::collections::HashMap;implSolution{pubfngroup_anagrams(strs:Vec<String>) -> Vec<Vec<String>>{letmut anagrams = HashMap::new();for s in strs {letmut cnt = [0;26]; s.bytes().for_each(|c| cnt[(c - b'a')asusize] += 1); anagrams.entry(cnt).or_insert(Vec::new()).push(s);} anagrams.values().cloned().collect()}}